package com.example.campusforumapi.service.impl;

import com.example.campusforumapi.dao.ActivityPartMapper;
import com.example.campusforumapi.entity.ActivityPartin;
import com.example.campusforumapi.entity.Role;
import com.example.campusforumapi.service.ActivityPartService;
import com.example.campusforumapi.service.ActivityService;
import com.example.campusforumapi.util.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityPartServiceImpl implements ActivityPartService {

    @Autowired
    private ActivityPartMapper activityPartMapper;

    @Override
    public PageResult getActPartRolePage(Integer page, Integer pageSize, Integer userId, Integer activityId, String status) {
        //1.设置分页参数
        PageHelper.startPage(page,pageSize);
//        2.执行查询
        List<ActivityPartin> actpartList = activityPartMapper.list(userId,activityId,status);
        Page<ActivityPartin> p = (Page<ActivityPartin>) actpartList;
//        3.封装PageResult对象
        PageResult pageResult = new PageResult(p.getResult(),p.getTotal(),p.getPageSize(),p.getPageNum());
        return pageResult;
    }

    @Override
    public int delActPart(List<Integer> userIds, List<Integer> activityIds) {
        return activityPartMapper.delActPart(userIds,activityIds);
    }

    @Override
    public int findsameUserId(Integer userId) {
        return activityPartMapper.findsameUserId(userId);
    }

    @Override
    public int findsameActivityId(Integer activityId) {
        return activityPartMapper.findsameActivityId(activityId);
    }

    @Override
    public int insertActPart(ActivityPartin activityPartin) {
        activityPartin.setRegisterTime(LocalDateTime.now());
        return activityPartMapper.insertActPart(activityPartin);
    }
}
